package cn.zhiwen.taskController;

import cn.zhiwen.util.LoadTask;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.impl.StdSchedulerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
public class TaskController {

    @RequestMapping("task")
    public String testTask(){
        Date date = new Date();
        long time = date.getTime();
        long times = time + 60000;
        LoadTask.timerTask(new Date(times),111);
        return "ok";
    }

    @RequestMapping("task1")
    public String testTask1(){
        LoadTask.timerTask("1 * * * * ? ",112);
        return "ok";
    }

    @RequestMapping("getTask")
    public Object getTaskScheduleJob() throws SchedulerException {
         Scheduler scheduler  = StdSchedulerFactory.getDefaultScheduler();
        List<String> triggerGroupNames = scheduler.getTriggerGroupNames();
        List<String> jobGroupNames = scheduler.getJobGroupNames();
        List<String> calendarNames = scheduler.getCalendarNames();
        triggerGroupNames.addAll(jobGroupNames);
        triggerGroupNames.addAll(calendarNames);
        return triggerGroupNames;
    }

    @RequestMapping("remove")
    public Object removeTask() throws SchedulerException {
        Scheduler scheduler  = StdSchedulerFactory.getDefaultScheduler();
        List<String> triggerGroupNames = scheduler.getTriggerGroupNames();
        return null;
    }
}
